﻿<Page
    x:Class="Microsoft.Media.CaptureClient.Sample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Microsoft.Media.CaptureClient.Sample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="RecordingStates">
                <VisualState x:Name="StartRecording">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="ButtonCaptureStart">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="False"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Recording">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ButtonCaptureStart">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ButtonCaptureStop">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="RecordingTime">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="RecordingIndicator">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation From="0" To="1" Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="RecordingIndicator"/>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="EndRecording">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ButtonCaptureStart">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ButtonCaptureStop">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="ButtonCaptureStop">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="False"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="PreviewOnly"/>
                <VisualState x:Name="NotRecording"/>
            </VisualStateGroup>
            <VisualStateGroup x:Name="InteractiveStates">
                <VisualState x:Name="Interacting">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ButtonContainer">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation To="1" Duration="0:0:0.25" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ButtonContainer"/>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="NotInteracting">
                    <Storyboard>
                        <DoubleAnimation To="0" Duration="0:0:0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ButtonContainer"/>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ButtonContainer">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid>
            <CaptureElement x:Name="captureElement"/>
            <TextBlock x:Name="RecordingIndicator" IsHitTestVisible="False" Visibility="Collapsed" Text="[REC]" HorizontalAlignment="Right" VerticalAlignment="Bottom" Style="{ThemeResource SubheaderTextBlockStyle}" Margin="10" Foreground="Red" FontWeight="Bold"/>
            <TextBlock x:Name="RecordingTime" IsHitTestVisible="False" Visibility="Collapsed" Text="0:00:00" HorizontalAlignment="Left" VerticalAlignment="Bottom" Style="{ThemeResource SubheaderTextBlockStyle}" Margin="10"/>
            <Grid Background="Transparent" Tapped="InteractionPanel_Tapped">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Viewbox x:Name="ButtonContainer" MaxWidth="300" VerticalAlignment="Center" Grid.Column="1">
                    <Grid x:Name="ButtonHost" Tapped="ButtonHost_Tapped">
                        <AppBarButton x:Name="ButtonCaptureStart" Click="ButtonCaptureStart_Click" Label="Start Broadcast">
                            <AppBarButton.Icon>
                                <FontIcon Glyph="&#x26AB;" Margin="0,0,0,2" Foreground="Red"/>
                            </AppBarButton.Icon>
                        </AppBarButton>
                        <AppBarButton x:Name="ButtonCaptureStop" Icon="Stop" Click="ButtonCaptureStop_Click" Visibility="Collapsed" Label="End Broadcast"/>
                    </Grid>
                </Viewbox>
            </Grid>
        </Grid>
    </Grid>
    <Page.BottomAppBar>
        <CommandBar Closed="CommandBar_Closed">
            <CommandBar.PrimaryCommands>
                <AppBarButton x:Name="ButtonStats" Icon="TwoBars" Label="stats">
                    <AppBarButton.Flyout>
                        <Flyout>
                            <StackPanel Margin="10,0,10,25">
                                <TextBlock Text="Fragments" Style="{ThemeResource SubheaderTextBlockStyle}"/>
                                <Grid Margin="10">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" MinWidth="65"/>
                                        <ColumnDefinition Width="Auto" MinWidth="65"/>
                                        <ColumnDefinition Width="Auto" MinWidth="65"/>
                                        <ColumnDefinition Width="Auto" MinWidth="65"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>

                                    <TextBlock Grid.Column="1" Text="Created" Style="{ThemeResource TitleTextBlockStyle}" Margin="5" HorizontalAlignment="Center"/>
                                    <TextBlock Grid.Column="2" Text="Queued" Style="{ThemeResource TitleTextBlockStyle}" Margin="5" HorizontalAlignment="Center"/>
                                    <TextBlock Grid.Column="3" Text="Sent" Style="{ThemeResource TitleTextBlockStyle}" Margin="5" HorizontalAlignment="Center"/>

                                    <TextBlock Grid.Row="1" Text="Audio" Style="{ThemeResource TitleTextBlockStyle}" Margin="5,5,5,10" VerticalAlignment="Center"/>
                                    <TextBlock x:Name="textAudioCreated" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" Margin="5" Text="0" Style="{ThemeResource BodyTextBlockStyle}"/>
                                    <TextBlock x:Name="textAudioQueued" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Center" Margin="5" Text="0" Style="{ThemeResource BodyTextBlockStyle}"/>
                                    <TextBlock x:Name="textAudioSent" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Center" Margin="5" Text="0" Style="{ThemeResource BodyTextBlockStyle}"/>

                                    <TextBlock Grid.Row="2" Text="Video" Style="{ThemeResource TitleTextBlockStyle}" Margin="5,5,5,10" VerticalAlignment="Center"/>
                                    <TextBlock x:Name="textVideoCreated" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" Margin="5" Text="0" Style="{ThemeResource BodyTextBlockStyle}"/>
                                    <TextBlock x:Name="textVideoQueued" Grid.Column="2" Grid.Row="2" HorizontalAlignment="Center" Margin="5" Text="0" Style="{ThemeResource BodyTextBlockStyle}"/>
                                    <TextBlock x:Name="textVideoSent" Grid.Column="3" Grid.Row="2" HorizontalAlignment="Center" Margin="5" Text="0" Style="{ThemeResource BodyTextBlockStyle}"/>
                                </Grid>
                                <TextBlock Text="Buffer" Style="{ThemeResource SubheaderTextBlockStyle}"/>
                                <StackPanel Margin="10">
                                    <ProgressBar x:Name="progressBufferSize" Maximum="10" Value="0"/>
                                    <Grid>
                                        <TextBlock Text="0MB"/>
                                        <TextBlock x:Name="textBufferSize" Text="0MB" HorizontalAlignment="Center"/>
                                        <TextBlock Text="10MB" HorizontalAlignment="Right"/>
                                    </Grid>
                                </StackPanel>
                                <TextBlock x:Name="textStatus" Visibility="Collapsed" Margin="10,0,10,10" TextWrapping="Wrap"/>
                            </StackPanel>
                        </Flyout>
                    </AppBarButton.Flyout>
                </AppBarButton>
                <AppBarButton x:Name="ButtonProfiles" Label="profiles" Icon="OpenLocal">
                    <AppBarButton.Flyout>
                        <Flyout Opened="ProfilesFlyout_Opened" Closed="ProfilesFlyout_Closed">
                            <local:ProfileViewer x:Name="Profiles" Margin="10,0,10,25"/>
                        </Flyout>
                    </AppBarButton.Flyout>
                </AppBarButton>
                <AppBarButton x:Name="ButtonSettings" Icon="Setting" Label="settings">
                    <AppBarButton.Flyout>
                        <Flyout>
                            <Grid Margin="10,0,10,25">
                                <local:SettingsView/>
                            </Grid>
                        </Flyout>
                    </AppBarButton.Flyout>
                </AppBarButton>
                <AppBarToggleButton x:Name="ButtonCamera" Label="front" Checked="ButtonCamera_Checked" Unchecked="ButtonCamera_Unchecked">
                    <Grid>
                        <FontIcon Glyph="&#xE114;" FontSize="12" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="6,8,0,0"/>
                        <FontIcon Glyph="&#xE13D;" FontSize="18" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,3,5"/>
                    </Grid>
                </AppBarToggleButton>
            </CommandBar.PrimaryCommands>
        </CommandBar>
    </Page.BottomAppBar>
</Page>